# class base for controller
from google.appengine.ext import webapp

# needed for display
from tools import settings_manager

class Edit(webapp.RequestHandler):
    '''
    '''
    def get(self):
        '''
        '''
        # get the language id
        locale_id = self.request.get('language')
        # get the size name
        size = self.request.get('size')

        # get the settings manager
        se_manager = settings_manager.SettingsManager(
                locale_id=locale_id, size=size)

        # display the author to edit
        template = se_manager.edit()
        return self.response.out.write(template)

class Save(webapp.RequestHandler):
    '''
    '''
    def post(self):
        '''
        '''
        # get the key to edit
        language_key = self.request.get('language_key')

        #
        se_manager = settings_manager.SettingsManager(
                language_key=language_key)

        # retrieve the key
        settings_key = self.request.get('settings_key')

        # cancel
        if not self.request.get('cancel') == '':
            pass

        # we save and display the author
        else:
            # get words
            wiki = self.request.get('wiki')
            author = self.request.get('author')
            collection = self.request.get('collection')
            exposition = self.request.get('exposition')
            picture = self.request.get('picture')
            contact = self.request.get('contact')
            start = self.request.get('start')
            end = self.request.get('end')
            select = self.request.get('select')

            # tools save the settings
            se_manager.save(
                    settings_key, wiki, author, collection,
                    exposition, picture, contact, start, end, select)

        # go to the index page
        return self.redirect(
                '/settings/edit?language=%s&size=%s' % (
                    se_manager.language.locale_id, se_manager.size.width))
